package com.example.saiweisi.service.impl.sysTemAdminService;

import com.example.saiweisi.controller.request.ReceptionAdminRequest;
import com.example.saiweisi.mapper.systemAdminMapper.ReceptionAdminMapper;
import com.example.saiweisi.model.ReceptionAdmin;
import com.example.saiweisi.service.interf.IReceptionAdminService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ReceptionAdminService implements IReceptionAdminService {
    @Autowired
    ReceptionAdminMapper receptionAdminMapper;
    @Override
    public PageInfo<ReceptionAdmin> page(ReceptionAdminRequest receptionAdminRequest) {
        PageHelper.startPage(receptionAdminRequest.getPageNum(), receptionAdminRequest.getPageSize());
        List<ReceptionAdmin> userList = receptionAdminMapper.receptionadminlistByCondition(receptionAdminRequest);
        return new PageInfo<>(userList);
    }

    @Override
    public void addreceptionadmin(ReceptionAdmin receptionAdmin) {
        //遍历数据库，将最大的 num加一 赋值给新用户，来达到生成唯一标识符的目的
        int s=1;
        List<ReceptionAdmin> list=receptionAdminMapper.getall();
        for (ReceptionAdmin a:list
        ) {
            if(Integer.parseInt(a.getReceptionAdminNum().substring(1))>s){
                s=Integer.parseInt(a.getReceptionAdminNum().substring(1));
            }
        }
//        String b=IdUtil.fastSimpleUUID();
//        Integer a=Integer.parseInt(b);
        receptionAdmin.setReceptionAdminNum("200"+Integer.toString(s+1));
        receptionAdminMapper.addreceptionadmin(receptionAdmin);
    }

    @Override
    public void deletereceptionadmin(Integer receptionAdminId) {
        receptionAdminMapper.deletereceptionadmin(receptionAdminId);
    }

    @Override
    public ReceptionAdmin getById(Integer receptionAdminId) {
        return receptionAdminMapper.getById(receptionAdminId);
    }

    @Override
    public void updatereceptionadmin(ReceptionAdmin receptionAdmin) {
        receptionAdminMapper.updatereceptionadmin(receptionAdmin);
    }

    @Override
    public void deletesreceptionadmin(List<Integer> receptionAdminIds) {
        for (Integer a:receptionAdminIds
             ) {
            receptionAdminMapper.deletereceptionadmin(a);
        }
    }

    @Override
    public void resetPassword(Integer receptionAdminId) {
        receptionAdminMapper.resetPassword(receptionAdminId);
    }
}
